package cs575.fantasyclient.ui;

import java.awt.Component;
import java.awt.Dimension;
import java.util.Map.Entry;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SpringLayout;

import cs575.common.Player;

public class StatDialog extends JDialog {

	
	public StatDialog(Player player){
		super();
		
		SpringLayout layout = new SpringLayout();
		setLayout(layout);
		
		JLabel nameLabel = new JLabel("Player Name");
		layout.putConstraint(SpringLayout.NORTH, nameLabel, 25, SpringLayout.NORTH, this);
		layout.putConstraint(SpringLayout.EAST, nameLabel, -5, SpringLayout.HORIZONTAL_CENTER, this);
		add(nameLabel);
		
		JLabel name = new JLabel(player.getName());
		layout.putConstraint(SpringLayout.NORTH, name, 25, SpringLayout.NORTH, this);
		layout.putConstraint(SpringLayout.WEST, name, 5, SpringLayout.HORIZONTAL_CENTER, this);
		add(name);
		
		JLabel positionLabel = new JLabel("Position");
		layout.putConstraint(SpringLayout.NORTH, positionLabel, 10, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.EAST, positionLabel, -5, SpringLayout.HORIZONTAL_CENTER, this);
		add(positionLabel);
		
		JLabel position = new JLabel(player.getPosition().toString());
		layout.putConstraint(SpringLayout.NORTH, position, 10, SpringLayout.SOUTH, nameLabel);
		layout.putConstraint(SpringLayout.WEST, position, 5, SpringLayout.HORIZONTAL_CENTER, this);
		add(position);
		
		Component last = positionLabel;
		
		for (Entry<String, Integer> e : player.getStats().entrySet()){
			JLabel statLabel = new JLabel(e.getKey());
			layout.putConstraint(SpringLayout.NORTH, statLabel, 10, SpringLayout.SOUTH, last);
			layout.putConstraint(SpringLayout.EAST, statLabel, -5, SpringLayout.HORIZONTAL_CENTER, this);
			add(statLabel);
			
			JLabel stat = new JLabel(e.getValue().toString());
			layout.putConstraint(SpringLayout.NORTH, stat, 10, SpringLayout.SOUTH, last);
			layout.putConstraint(SpringLayout.WEST, stat, 5, SpringLayout.HORIZONTAL_CENTER, this);
			add(stat);
			
			last = statLabel;
		}
		
		setMinimumSize(new Dimension(300, 300));
		setPreferredSize(new Dimension(300, 300));
	}
}
